﻿using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Net;
using Business.Logic;

namespace MobileEntitiesTest
{
    /// <summary>
    /// Summary description for CookieCollectionTest
    /// </summary>
    [TestClass]
    public class CookieCollectionTest
    {
        //[TestMethod]
        //public void SetCookiesFromResponse_TwoParams_FirstStored()
        //{
        //    var cookies = new Business.Entities.CookieCollection();
        //    var headers = new WebHeaderCollection();
        //    headers.Add("set-cookie", "sdfasdf=bfber;badfbbfsd=cvxzvcxz;");
        //    cookies.SetCookiesFromResponse(headers);
        //    Assert.AreEqual(1, cookies.Count);
        //}

        //[TestMethod]
        //public void SetCookiesFromResponse_OneParams_Stored()
        //{
        //    var cookies = new Business.Entities.CookieCollection();
        //    var headers = new WebHeaderCollection();
        //    headers.Add("set-cookie", "sdfasdf=bfber");
        //    cookies.SetCookiesFromResponse(headers);
        //    Assert.AreEqual(1, cookies.Count);
        //}

        //[TestMethod]
        //public void SetCookiesFromResponse_OneParamEndWithSemiCOlon_Stored()
        //{
        //    var cookies = new Business.Entities.CookieCollection();
        //    var headers = new WebHeaderCollection();
        //    headers.Add("set-cookie", "sdfasdf=bfber;");
        //    cookies.SetCookiesFromResponse(headers);
        //    Assert.AreEqual(1, cookies.Count);
        //}

        //[TestMethod]
        //public void SetCookiesFromResponse_TwoCookies_TwoStored()
        //{
        //    var cookies = new Business.Entities.CookieCollection();
        //    var headers = new WebHeaderCollection();
        //    headers.Add("set-cookie", "sdfasdf=bfber;");
        //    headers.Add("set-cookie", "Bølle=knus");
        //    cookies.SetCookiesFromResponse(headers);
        //    Assert.AreEqual(2, cookies.Count);
        //}

        //[TestMethod]
        //public void SetCookiesFromResponse_DifferentCasingInKeyword_Stored()
        //{
        //    var cookies = new Business.Entities.CookieCollection();
        //    var headers = new WebHeaderCollection();
        //    headers.Add("sEt-coOkie", "sdfasdf=bfber;");
        //    headers.Add("set-coOKie", "ealle= knus");
        //    cookies.SetCookiesFromResponse(headers);
        //    Assert.AreEqual(2, cookies.Count);
        //}

        //[TestMethod]
        //public void SetCookiesFromResponse_CrappyInput1_NoFail()
        //{
        //    var cookies = new Business.Entities.CookieCollection();
        //    var headers = new WebHeaderCollection();
        //    headers.Add("sEt-coOkie", "aewF;;Gaer;Bv,b;;GSdfbhNL;NGse dbcbv;");
        //    headers.Add("set-coOKie", "HEAHAEHAE====AHE=");
        //    headers.Add("set-coOKie", ";A=B");
        //    headers.Add("set-coOKie", "q=1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;");
        //    headers.Add("set-coOKie", "");
        //    headers.Add("set-coOKie", null);
        //    cookies.SetCookiesFromResponse(headers);
        //    Assert.AreEqual(2, cookies.Count);
        //}
        
        [ExpectedException(typeof(GogTasksException))]
        [TestMethod]
        public void ParseUrlFromPhase2_1()
        {
            GoogleLogin gl = new GoogleLogin();
            gl.ParseUrlFromPhase2("asdflfkasdlfkasdl");
        }
        [TestMethod]
        [ExpectedException(typeof(GogTasksException))]
        public void ParseUrlFromPhase2_2()
        {
            GoogleLogin gl = new GoogleLogin();
            gl.ParseUrlFromPhase2("faewfaewf_url=&#39;_faewfaewfaewf");
            
        }

        
        [TestMethod]
        public void ParseUrlFromPhase2_3()
        {
            GoogleLogin gl = new GoogleLogin();
            var url = gl.ParseUrlFromPhase2("faewfaewf_url=&#39;_faewfaewfaewf_\"></head>");
            Assert.AreEqual("_faewfaewfaewf_", url);
            
        }

        [TestMethod]
        public void ParseLoginForm_a_b()
        {
            GoogleLogin gl = new GoogleLogin();
            gl.ParseLoginForm("fsdalkflsklfkdlfkl");
        }

        [TestMethod]
        public void ParseLoginForm_oneKeyVal()
        {
            GoogleLogin gl = new GoogleLogin();
            gl.ParseLoginForm(@"<html><input name=""TEST"" value=""FOUR""></html>");
            Assert.AreEqual("FOUR", gl.KeyVal["TEST"]);
        }
        [TestMethod]
        public void ParseLoginForm_TwoKeyVal()
        {
            GoogleLogin gl = new GoogleLogin();
            gl.ParseLoginForm(@"<html><input name=""TEST"" value=""FOUR""><input name=""ZEBRA"" value=""STRIPES""></html>");
            Assert.AreEqual("FOUR", gl.KeyVal["TEST"]);
            Assert.AreEqual("STRIPES", gl.KeyVal["ZEBRA"]);
            Assert.AreEqual(2, gl.KeyVal.Keys.Count);
        }
    }
}
